"use strict";

angular.module('app.sensor', ['ui.router', 'restangular'])
.filter('type_filter', function () {
    return function (input) {
        // input是我们传入的字符串
        var ss = input.match(/(\S*)\(/)[1];
        return ss;
    }
})
.filter('length_filter', function () {
    return function (input) {
        // input是我们传入的字符串
        var type = input.match(/(\S*)\(/)[1];
        if (type == "double" || type == "float") {//double(12,2)
            var length = input.match(/\((\S*)\,/)[1];
        } else {//int(4)
            var length = input.match(/\((\S*)\)/)[1];
        }
        return length;
    }
})
.filter('xiao_filter', function () {
    return function (input) {
        // input是我们传入的字符串
        var type = input.match(/(\S*)\(/)[1];
        if (type == "double" || type == "float") {//double(12,2)
            var xiao = input.match(/\,(\S*)\)/)[1];
        } else {//int(4)
            var xiao = "0";
        }
        return xiao;
    }
})
.filter('signalfilter', function () {
    return function (input) {
        // input是我们传入的字符串
        if (input < 20)
            return "styles/img/弱信号.png";
        else
            return "styles/img/强信号.png";
    }
})

.filter('ele_chargefilter', function () {
    return function (input) {
        // input是我们传入的字符串
        if (input == "1")
            return "styles/img/多电量.png";
        else
            return "styles/img/多电量.png";
    }
})
.filter('status', function () {
    return function (input) {
        // input是我们传入的字符串
        if (input == "0")
            return "Offline";
        else
            return "Online";
    }
})
.filter('handle_status', function () {
    return function (input) {
        // input是我们传入的字符串
        if (input == "0")
            return "未处理";
        else
            return "已处理";
    }
})
.config(function ($stateProvider, RestangularProvider) {

    $stateProvider
         .state('app.sensor', {
             abstract: true,
             data: {
                 title: '设备管理'
             }
         })
       .state('app.sensor.charts', {
              url: '/sensorcharts/:deviceid',
              views: {
                  "content@app": {
                      templateUrl: 'sensor/views/sensorcharts.html',
                      controller:'SensorChartsCtrl'
                  }
              },
              data: {
                  title: '数据曲线'
              }
       })
        .state('app.sensor.datacharts', {
            url: '/datacharts',
            views: {
                "content@app": {
                    templateUrl: 'sensor/views/datacharts.html',
                    controller: 'DataChartsCtrl'
                }
            },
            data: {
                title: '历史数据图表配置'
            }
        })
         .state('app.sensor.watchcharts', {
             url: '/watchcharts/:deviceid',
             views: {
                 "content@app": {
                     templateUrl: 'sensor/views/watchcharts.html',
                     controller: 'WatchChartsCtrl'
                 }
             },
             data: {
                 title: '历史数据图表查看'
             }
         })
        .state('app.sensor.loginlog', {
            url: '/loginlog',
            views: {
                "content@app": {
                    templateUrl: 'sensor/views/loginlog.html',
                    controller: 'LoginLogCtrl'
                }
            },
            data: {
                title: '登录日志'
            }
        })
        .state('app.sensor.worklog', {
            url: '/worklog',
            views: {
                "content@app": {
                    templateUrl: 'sensor/views/worklog.html',
                    controller: 'WorkLogCtrl'
                }
            },
            data: {
                title: '工作日志'
            }
        })
        .state('app.sensor.perlog', {
            url: '/perlog',
            views: {
                "content@app": {
                    templateUrl: 'sensor/views/perlog.html',
                    controller: 'PerLogCtrl'
                }
            },
            data: {
                title: '个人日志'
            }
        })
         .state('app.sensor.device', {
             url: '/device',
             views: {
                 "content@app": {
                     templateUrl: 'sensor/views/device.html',
                     controller: 'DeviceCtrl'
                 }
             },
             data: {
                 title: '设备管理'
             }
         })
         .state('app.sensor.parameters', {
             url: '/parameters',
             views: {
                 "content@app": {
                     templateUrl: 'sensor/views/parameters.html',
                     controller: 'ParametersCtrl'
                 }
             },
             data: {
                 title: '设备参数'
             }
         })
        .state('app.sensor.data', {
            url: '/data',
            views: {
                "content@app": {
                    templateUrl: 'sensor/views/data.html',
                    controller: 'DataCtrl'
                }
            },
            data: {
                title: '实时数据'
            }
        })
        .state('app.sensor.historicaldata', {
            url: '/historicaldata/:port/:deviceid',
            views: {
                "content@app": {
                    templateUrl: 'sensor/views/historicaldata.html',
                    controller: 'HistoricaldataCtrl'
                }
            },
            data: {
                title: '历史数据'
            }
        })

        .state('app.sensor.alert', {
            url: '/alert',
            views: {
                "content@app": {
                    templateUrl: 'sensor/views/alert.html',
                    controller: 'AlertCtrl'
                }
            },
            data: {
                title: '警报处理'
            }
        })

        .state('app.sensor.alertsite', {
            url: '/alertsite',
            views: {
                "content@app": {
                    templateUrl: 'sensor/views/alertsite.html',
                    controller: 'AlertsiteCtrl'
                }
            },
            data: {
                title: '警报设置'
            }
        })
        .state('app.sensor.maps', {
            url: '/maps',
            views: {
                "content@app": {
                    templateUrl: 'sensor/views/maps.html',
                    controller: 'MapsCtrl'
                }
            },
            data: {
                title: '地图'
            }
        })
});


